package com.sinosoft.jwjw.component.service.imp.system;

import com.sinosoft.jwjw.base.BaseCrudMapper;
import com.sinosoft.jwjw.base.BaseCrudServiceImp;
import com.sinosoft.jwjw.component.mapper.system.SDataDictionaryCodeNodeMapper;
import com.sinosoft.jwjw.component.model.system.SDataDictionaryCodeNode;
import com.sinosoft.jwjw.component.service.system.SDataDictionaryCodeNodeService;
import com.sinosoft.jwjw.utils.ConvertUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class SDataDictionaryCodeNodeImp extends BaseCrudServiceImp<SDataDictionaryCodeNode,String> implements SDataDictionaryCodeNodeService {

    @Autowired
    private SDataDictionaryCodeNodeMapper sDataDictionaryCodeNodeMapper;

    @Override
    public BaseCrudMapper<SDataDictionaryCodeNode, String> getMapper() {
        return sDataDictionaryCodeNodeMapper;
    }

    @Override
    /**
     * @Description:  TODO
     * @param codeType
     * @return:  java.lang.String
     * @Author:  bankPro
     * @CreateDate:  2019/2/19 18:33
     */
    public String queryCodeByType(String codeType) {

       JSONArray  jsonArray =  sDataDictionaryCodeNodeMapper.queryCodeByType(codeType);
       StringBuffer  selectStr = new StringBuffer();
        selectStr.append(" <option value=''>请选择</option>");
       if (jsonArray.size() > 0){
           for (int i=0; i<jsonArray.size();i++){
               JSONObject jsonObject = jsonArray.getJSONObject(i);
               String code = ConvertUtil.toSqlString(jsonObject.get("code"));
               String name = ConvertUtil.toSqlString(jsonObject.get("name"));
               selectStr.append(" <option value='"+code+"'>"+name+"</option>");
           }
       }

        return selectStr.toString();
    }
}
